﻿@{
    Html.AddScriptParts(Url.Content("~/Plugins/SevenSpikes.Nop.AjaxFilters/Scripts/AttributeFilter.js"));
}

@model AttributeFilterModel7Spikes

@using System.Text;
@using SevenSpikes.Nop.AjaxFilters.Models.AttributeFilter;
@using SevenSpikes.Nop.AjaxFilters.Common;
@using SevenSpikes.Nop.AjaxFilters.Domain;


@if (Model.NopAjaxFiltersSettings.FiltersUIMode == FiltersUIMode.UseDropdowns)
{
    var stringBuilder = new StringBuilder();

    foreach (AttributeFilterGroup attributeFilterGroup in Model.AttributeFilterGroups)
    {
        stringBuilder.Append("#attributeFiltersDropDown");
        stringBuilder.Append(attributeFilterGroup.Id);
        stringBuilder.Append(",");
    }

    string attributeFilterPanelsSelector = stringBuilder.ToString().TrimEnd(new[] { ',' });
    
    <script type="text/javascript">

        $(document).ready(function () {

            $("@attributeFilterPanelsSelector").jDropDown();
        })

    </script>
}



<div class="attributeFilterPanel7Spikes">

@{
    int optionsGroupIndex = 0;
    int currentZIndex = Model.AttributeFilterGroups.Count + 100;
}

@foreach (AttributeFilterGroup attributeFilterGroup in Model.AttributeFilterGroups)
{
    Func<int, HelperResult> attributeOptionsHtml = 
    @<text>
        @foreach (AttributeFilterItem attributeFilterItem in attributeFilterGroup.FilterItems)
        {
            string filterItemCssClass = "filterItemUnselected";

            if (attributeFilterItem.FilterItemState == FilterItemState.Checked)
            {
                filterItemCssClass = "filterItemSelected";
            }

            string productVariantAttributeIds = String.Empty;

            foreach (int productVariantAttributeId in attributeFilterItem.ProductVariantAttributeIds)
            {
                productVariantAttributeIds += productVariantAttributeId + ",";
            }

            productVariantAttributeIds = productVariantAttributeIds.TrimEnd(new[] { ',' });
                    
            <li>
                <a class="@filterItemCssClass" data-option-ids="@productVariantAttributeIds" data-optionsGroupId="@String.Concat(attributeFilterGroup.Id, "-", attributeFilterItem.Name)">@attributeFilterItem.Name</a>
            </li>
        }
     </text>;
    
    <div class="block block-category-navigation">
        <div class="title">
            <a class="toggleControl">@attributeFilterGroup.Name</a>
            <a class="clearFilterOptions">@T("SevenSpikes.NopAjaxFilters.Client.Common.Clear")</a>
           <div class="clear"></div>
        </div>
        <div class="clear"></div>

            @if (Model.NopAjaxFiltersSettings.FiltersUIMode == FiltersUIMode.UseCheckboxes)
            {
                <div class="filtersGroupPanel" data-optionsGroupId="@attributeFilterGroup.Id">
                    <ul>
                        @attributeOptionsHtml(0)
                    </ul>
                </div>
            }
            else if (Model.NopAjaxFiltersSettings.FiltersUIMode == FiltersUIMode.UseDropdowns)
            {
                <div class="filtersGroupPanel filtersDropDownPanel" data-optionsGroupId="@attributeFilterGroup.Id" style="z-index: @currentZIndex;">
                    <div id="@String.Concat("attributeFiltersDropDown", attributeFilterGroup.Id)" class="filtersDropDown">
                        <div>
                            <p></p>
                        </div>
                        <ul>
                            <li>
                                <a class="allFilterDropDownOptions selected">@T("SevenSpikes.NopAjaxFilters.Client.Common.All")</a>
                            </li>
                            @attributeOptionsHtml(0)
                        </ul>
                    </div>
                </div>
            }
        
    </div>
    
    optionsGroupIndex++;
    currentZIndex--;

}

</div>